package me.guowenlong.transformer.bean;

import java.util.concurrent.TimeUnit;

import io.reactivex.Single;

/**
 * desc   : rxjava的retrywhen的相关参数
 * author : guowenlong
 * Email  : guowenlong20000@gmail.com
 * time   : 2019年01月08日15 : 09
 */
public class RetryBean {
    private int maxRetries = 0;
    private int retryDelay = 100;
    private TimeUnit timeUnit = TimeUnit.MILLISECONDS;
    private Single<Boolean> condition = Single.just(false);

    public RetryBean() {}

    public RetryBean(int maxRetries, int retryDelay, TimeUnit timeUnit, Single<Boolean> condition) {
        this.maxRetries = maxRetries;
        this.retryDelay = retryDelay;
        this.timeUnit = timeUnit;
        this.condition = condition;
    }

    public int getMaxRetries() {
        return maxRetries;
    }

    public int getRetryDelay() {
        return retryDelay;
    }

    public TimeUnit getTimeUnit() {
        return timeUnit;
    }

    public Single<Boolean> getCondition() {
        return condition;
    }

    /**
     * 不重试
     */
    public static RetryBean getNilRetryBean() {
        return new RetryBean();
    }

    /**
     * 重试一次 无操作
     */
    public static RetryBean getOneTimeRetryBean() {
        return getOneTimeRetryBean(Single.just(false));
    }

    /**
     * 重试一次 自定义操作
     */
    public static RetryBean getOneTimeRetryBean(Single<Boolean> condition) {
        return new RetryBean(1, 100, TimeUnit.MILLISECONDS, condition);
    }

    /**
     * 完全自定义重试条件
     */
    public static RetryBean getCustomRetryBean(int maxRetries, int retryDelay, TimeUnit timeUnit, Single<Boolean> condition) {
        return new RetryBean(maxRetries, retryDelay, timeUnit, condition);
    }
}